package com.tobby.demo.infinispan.weather;

import java.util.Random;
import java.util.concurrent.TimeUnit;

import org.infinispan.Cache;

public class RandomWeatherService extends CachingWeatherService {

	final Random random;

	public RandomWeatherService(Cache<String, LocationWeather> cache) {
		super(cache);
		random = new Random();
	}

	@Override
	public LocationWeather fetchWeather(String location) {
		try {
			TimeUnit.MILLISECONDS.sleep(2000);

		}
		catch (InterruptedException e) {
			e.printStackTrace();
		}
		String[] split = location.split(",");
		return new LocationWeather(random.nextFloat() * 20f + 5f, "sunny",
				split[1].trim());
	}

}
